#include <iostream>
#include <sstream>
#include <opencv2/opencv.hpp>

using namespace cv;
using namespace std;

/*用于从图片生成视频*/

int main(int, char **)
{
    Mat srcImg;
    VideoWriter writer;
    writer.open("cam0.avi", VideoWriter::fourcc('M', 'J', 'P', 'G'), 25, cv::Size(1280, 800));
    int counter = 1020;

    string imgPath = "/home/llrt/文档/ModuleData/cam0/data/";
    string imgHead = "10000000";
    string imgTail = "0000000.png";

    while (true)
    {
        stringstream ss;
        string cou;
        ss << counter;
        ss >> cou;
        cout << imgPath + imgHead + cou + imgTail << endl;
        srcImg = imread(imgPath + imgHead + cou + imgTail);

        if (srcImg.empty())
        {
            counter += 2;
            continue;
        }

        if (counter >= 67096)
        {
            break;
        }

        // imshow("srcImg", srcImg);
        // waitKey(0);
        writer << srcImg;
        if (counter == 1398)
        {
            imgHead = "1000000";
            counter = 57356;
            continue;
        }
        counter += 2;
    }
    cout << "video generating finished" << endl;
}
